<?php
	// ----------------------------------------------------
	// Beschreibung Skript:
	//   Gibt die aktuellen Settings aus und speichert 
	//   Änderungen an diesen Settings.
	//
	// ----------------------------------------------------
	// Änderungen:
	//
	// ----------------------------------------------------


	// ------------------------------------------------------
	// Initialisiert das Skript.
	// ------------------------------------------------------  
	require_once 'loader.php';

	// ------------------------------------------------------
	// Verarbeitet POST Daten und speichert diese.
	// ------------------------------------------------------
	//  
 	$ExterUserID = 'michelle.rangosch';
	$ExterUserID = 'andy';
// 	$ExterUserID = 'werner.pfister';
	$Member->getUserData($ExterUserID);
	$Settings->getSettingsData();
	//
	if(strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
		set_POSTtoSettings($Settings);
		$Settings->setSettingsData();
	}

	// ------------------------------------------------------
	// Header laden.
	// ------------------------------------------------------  
	$Header->printHeader();
	
	// ------------------------------------------------------
	// Settings laden.
	// ------------------------------------------------------
	// Print settings.
	$isSuperUser = $Member->isSuperAdmin();
	$arrLabel = Array('InitialMemberAmount:', 'MaxShareAssociationFee:', 'FamilyDiscount:', 'CommitteeAmount:', 'OnceFAASAmountAdult:', 'OnceFAASAmountChild:');
	$arrValue = Array($Settings->InitialMemberAmount, $Settings->MaxShareAssociationFee, 
					  $Settings->FamilyDiscount, $Settings->CommitteeAmount, 
					  $Settings->OnceFAASAmountAdult, $Settings->OnceFAASAmountChild);
	If ($isSuperUser) {
		array_push($arrLabel, 'Debug:');
		array_push($arrValue, $Settings->Debug);
	}
	//
	print('<form Action="set_settings.php" method="post">'."\n");
	print('<input type="hidden" name="isSuperUser" value="'.$isSuperUser.'">'."\n");
	print('<table>'."\n");
	print('  <tbody>'."\n");
	For ($ix = 0; $ix < count($arrLabel); $ix++) {
		print('    <tr>'."\n");
		print('      <td>'.$arrLabel[$ix].'</td>'."\n");
		print('      <td>'.$arrValue[$ix].'</td>'."\n");
		print('    </tr>'."\n");
	}
	print('    <tr>'."\n");
	print('      <td>&nbsp;</td><td align="right"><input type="submit" value="Bearbeiten"></td>'."\n");
	print('    </tr>'."\n");
	print('  </tbody>'."\n");
	print('</table>'."\n");
	print('</form>'."\n");
	//
	print("<br />"."\n");
	//

	
	/**
	 * Fill the data from POST to User
	 */
	function set_POSTtoSettings($settings) {
		if(strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
			// Set fields of Settings.
			$settings->InitialMemberAmount = htmlspecialchars($_POST['InitialMemberAmount']);
			$settings->MaxShareAssociationFee = htmlspecialchars($_POST['MaxShareAssociationFee']);
			$settings->FamilyDiscount = htmlspecialchars($_POST['FamilyDiscount']);
			$settings->CommitteeAmount = htmlspecialchars($_POST['CommitteeAmount']);
			$settings->OnceFAASAmountAdult = htmlspecialchars($_POST['OnceFAASAmountAdult']);
			$settings->OnceFAASAmountChild = htmlspecialchars($_POST['OnceFAASAmountChild']);
			$settings->Debug = htmlspecialchars($_POST['Debug']);
		}
	}
	
		// ------------------------------------------------------
	// Footer laden.
	// ------------------------------------------------------
	include 'footer.php';
?>